package com.tjsinfo.tjsoa.addresslist.dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.tjsinfo.tjsoa.addresslist.vo.AddressListUser;

/**
 * A data access object (DAO) providing persistence and search support for
 * AddressListUser entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.AddressListUser
 * @author MyEclipse Persistence Tools
 */

public class AddressListUserDAO extends HibernateDaoSupport implements IAddressListUserDAO {
	private static final Log log = LogFactory.getLog(AddressListUserDAO.class);
	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#save(com.tjsinfo.tjsoa.addresslist.AddressList_User.AddressListUser)
	 */
	public String save(AddressListUser transientInstance) {
		log.debug("saving AddressListUser instance");
		String i = "";
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
			i = transientInstance.getId();
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
		return i;
	}
	
	public void update(AddressListUser transientInstance) {
		getHibernateTemplate().update(transientInstance);
	}
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#delete(com.tjsinfo.tjsoa.addresslist.AddressList_User.AddressListUser)
	 */
	public void delete(AddressListUser persistentInstance) {
		log.debug("deleting AddressListUser instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findById(java.lang.Integer)
	 */
	public AddressListUser findById(java.lang.String id) {
		log.debug("getting AddressListUser instance with id: " + id);
		try {
			AddressListUser instance = (AddressListUser) getHibernateTemplate()
					.get(
							"com.tjsinfo.tjsoa.addresslist.vo.AddressListUser",
							id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByExample(com.tjsinfo.tjsoa.addresslist.AddressList_User.AddressListUser)
	 */
	public List findByExample(AddressListUser instance) {
		log.debug("finding AddressListUser instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding AddressListUser instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from AddressListUser as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByUserSort(java.lang.Object)
	 */
	public List findByUserSort(Object userSort) {
		return findByProperty(USER_SORT, userSort);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByUserId(java.lang.Object)
	 */
	public List findByUserId(Object userId) {
		return findByProperty(USER_ID, userId);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByUserName(java.lang.Object)
	 */
	public List findByUserName(Object userName) {
		return findByProperty(USER_NAME, userName);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByMobile(java.lang.Object)
	 */
	public List findByMobile(Object mobile) {
		return findByProperty(MOBILE, mobile);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByEmail(java.lang.Object)
	 */
	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByCompany(java.lang.Object)
	 */
	public List findByCompany(Object company) {
		return findByProperty(COMPANY, company);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findBySector(java.lang.Object)
	 */
	public List findBySector(Object sector) {
		return findByProperty(SECTOR, sector);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByDuty(java.lang.Object)
	 */
	public List findByDuty(Object duty) {
		return findByProperty(DUTY, duty);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByCompanyPhone(java.lang.Object)
	 */
	public List findByCompanyPhone(Object companyPhone) {
		return findByProperty(COMPANY_PHONE, companyPhone);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByCompanyFax(java.lang.Object)
	 */
	public List findByCompanyFax(Object companyFax) {
		return findByProperty(COMPANY_FAX, companyFax);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByCompanyAddress(java.lang.Object)
	 */
	public List findByCompanyAddress(Object companyAddress) {
		return findByProperty(COMPANY_ADDRESS, companyAddress);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByCompanyPostal(java.lang.Object)
	 */
	public List findByCompanyPostal(Object companyPostal) {
		return findByProperty(COMPANY_POSTAL, companyPostal);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByHomeAddress(java.lang.Object)
	 */
	public List findByHomeAddress(Object homeAddress) {
		return findByProperty(HOME_ADDRESS, homeAddress);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByHomePostal(java.lang.Object)
	 */
	public List findByHomePostal(Object homePostal) {
		return findByProperty(HOME_POSTAL, homePostal);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByHomePhone(java.lang.Object)
	 */
	public List findByHomePhone(Object homePhone) {
		return findByProperty(HOME_PHONE, homePhone);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByQq(java.lang.Object)
	 */
	public List findByQq(Object qq) {
		return findByProperty(QQ, qq);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByMsn(java.lang.Object)
	 */
	public List findByMsn(Object msn) {
		return findByProperty(MSN, msn);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByBlog(java.lang.Object)
	 */
	public List findByBlog(Object blog) {
		return findByProperty(BLOG, blog);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByRemarks(java.lang.Object)
	 */
	public List findByRemarks(Object remarks) {
		return findByProperty(REMARKS, remarks);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findByState(java.lang.Object)
	 */
	public List findByState(Object state) {
		return findByProperty(STATE, state);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all AddressListUser instances");
		try {
			String queryString = "from AddressListUser";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#merge(com.tjsinfo.tjsoa.addresslist.AddressList_User.AddressListUser)
	 */
	public AddressListUser merge(AddressListUser detachedInstance) {
		log.debug("merging AddressListUser instance");
		try {
			AddressListUser result = (AddressListUser) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#attachDirty(com.tjsinfo.tjsoa.addresslist.AddressList_User.AddressListUser)
	 */
	public void attachDirty(AddressListUser instance) {
		log.debug("attaching dirty AddressListUser instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_User.IAddressListUserDAO#attachClean(com.tjsinfo.tjsoa.addresslist.AddressList_User.AddressListUser)
	 */
	public void attachClean(AddressListUser instance) {
		log.debug("attaching clean AddressListUser instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IAddressListUserDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IAddressListUserDAO) ctx.getBean("AddressListUserDAO");
	}
}